﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Project.Engine.Control;
using Project.Module.Model;
using Project.Module.Model.CMS;
using Project.Module.DAO.CMSBL;
using Project.Module.DAO.BL;
using Project.Engine.Utilities;

namespace Project.Module.View.CMS
{
    public class CMSThemSanPham : BasePageRazor
    {
        public string displayAdmin = string.Empty;
        public List<CategoryModel> listCate = null;
        public List<SupplierModel> listSupplier = null;
        public List<ProductModel> listProduct = null;

        private SupplierBL supplierBl = new SupplierBL();
        private CategoryBL cateBl = new CategoryBL();
        private ProductBL productBl = new ProductBL();

        protected override void InitializePage()
        {
            base.InitializePage();
            if (Session["username_ad"] != null && ((string)(Session["username_ad"])).Length > 0)
            {
                displayAdmin = (string)(Session["username_ad"]);
                listCate = cateBl.GetAllCate();
                listSupplier = supplierBl.GetAllSupplier();
                GetListProduct();
            }
        }

        private void GetListProduct() {
            listProduct = productBl.GetListProduct();
            if (listProduct != null) {
                foreach (var item in listProduct) {
                    item.SupplierName = supplierBl.GetSupplierByID(item.SupplierID);
                    item.CateName = ConvertUtil.GetCateNameByCateId(item.CatagoryId);
                }
            }
        }
    }
}
